import sys
import os

os.environ['MTP_CONFIG'] = os.path.abspath(sys.argv[1])
sys.path.append(os.getcwd())

from mtp.pythonmodel import *
from mtp.config.environment import configure_mtp, config

class plugin:
    @classmethod
    def list(k):
        for plugin in config['mtp.all_plugins'].iterkeys():
            enabled = (plugin in config['mtp.plugins'])
            print "plugin: %s enabled:%s" % (plugin, enabled)

    @classmethod
    def setup(k, plugin):
        config['mtp.plugins'][plugin].setup()

    @classmethod
    def takedown(k, plugin):
        config['mtp.plugins'][plugin].takedown()
        

class trac:
    @classmethod
    def import_(k, path):
        from mtp.tools.import_trac import convert_all
        convert_all(os.path.abspath(path))


def run():
    configure_mtp()

    command = sys.argv[2]
    action = sys.argv[3]

    if action in ('import',):
        action += '_'
    
    import mtp.tools.mtp_conf as this

    cobj = getattr(this, command)
    aobj = getattr(cobj, action)
    aobj(*sys.argv[4:])
    
if __name__ == '__main__':
    run()

